//
//  JXTHUDHelper.m
//  jiaoxuetong
//
//  Created by zhaoliang on 15/6/26.
//  Copyright (c) 2015年 zhaoliang. All rights reserved.
//

#import "JXTHUDHelper.h"
#import "MBProgressHUD.h"
#import "UIView+LayoutMethods.h"

@implementation JXTHUDHelper

+ (void)showHUDText:(NSString *)text type:(NSString *)type inView:(UIView *)view
{
    if (view == nil) {
        view = [[[UIApplication sharedApplication] windows] lastObject];
    }
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"hud_ic_%@", type]]];
    hud.cornerRadius = 3;
    hud.removeFromSuperViewOnHide = YES;
    hud.mode = MBProgressHUDModeCustomView;
    hud.detailsLabelFont = [UIFont systemFontOfSize:16];
    hud.detailsLabelText = text;
    hud.customView.width = 34;
    hud.customView.height = 34;
    [view addSubview:hud];
    [hud hide:YES afterDelay:1];
}

+ (void)showHUDText:(NSString *)text type:(NSString *)type inView:(UIView *)view withBlock:(void (^)())block
{
    if (view == nil) {
        view = [[[UIApplication sharedApplication] windows] lastObject];
    }
    MBProgressHUD *hud = [[MBProgressHUD alloc] init];
    hud.cornerRadius = 3;
    hud.removeFromSuperViewOnHide = YES;
    hud.mode = MBProgressHUDModeCustomView;
    hud.detailsLabelFont = [UIFont systemFontOfSize:16];
    hud.detailsLabelText = text;
    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"hud_ic_%@", type]]];
    hud.customView.width = 34;
    hud.customView.height = 34;
    [view addSubview:hud];
    
    [hud showAnimated:YES whileExecutingBlock:^{
        sleep(2);
    } completionBlock:^{
        block();
    }];
}


+ (void)showHUDText:(NSString *)text type:(NSString *)type inView:(UIView *)view mode:(NSInteger)HUDMode
{
    if (view == nil) {
        view = [[[UIApplication sharedApplication] windows] lastObject];
    }
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"hud_ic_%@", type]]];
    hud.customView.width = 34;
    hud.customView.height = 34;
    hud.cornerRadius = 3;
    hud.removeFromSuperViewOnHide = YES;
    hud.mode = HUDMode;
    hud.detailsLabelFont = [UIFont systemFontOfSize:16];
    hud.detailsLabelText = text;
    [view addSubview:hud];
    [hud hide:YES afterDelay:1];
}



@end
